// 所有模块都通过 define 来定义
define(function (require, exports, module) {
    //-S-手机号码验证
    jQuery.validator.addMethod("maxAmount", function (value, element) {
        var value = parseInt(value);
        var max_amount = parseInt($('#cash_single_max_amount_limit').val());
        if (max_amount) {
            if (value > max_amount) {
                return false;
            } else {
                return true;
            }
        } else {
            return true;
        }
    }, "最高金额不得高于于" + $('#cash_single_max_amount_limit').val() + "元");
//-E-手机号码验证
// -S-手机号码验证
    jQuery.validator.addMethod("minAmount", function (value, element) {
        var value = parseInt(value);
        var typeAccount = parseInt($('#userNature').val());
        var min_amount = (typeAccount == 1) ? parseInt($('#cash_single_min_amount_limit').val()) : parseInt($('#comp_cash_single_max_amount_limit').val());
        if (min_amount) {
            if (value < min_amount) {
                return false;
            } else {
                return true;
            }
        } else {
            return true;
        }
    }, "最低金额不得低于" + ((parseInt($('#userNature').val()) == 1) ? parseInt($('#cash_single_min_amount_limit').val()) : parseInt($('#comp_cash_single_max_amount_limit').val())) + "元");
//-E-手机号码验证
// -S-手机号码验证
    jQuery.validator.addMethod("userMoney", function (value, element) {
        var value = parseInt(value);
        var rest = parseInt($('#user_rest_money').val());
        if (rest) {
            if (value <= rest) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }, "余额不足,最高金额不得高于" + parseInt($('#user_rest_money').val())+ "元");
//-E-手机号码验证
    require("common");
    $("#withdrawals-form").validate({
        rules: {
            'amount': {
                required: true,userMoney:true, minAmount: true, maxAmount: true,
            },
            'payPwd': {
                required: true
            }
        },
        messages: {
            'amount': {
                required: "请输入提现金额"
            },
            'payPwd': {
                required: '请输入支付密码'
            }
        },
        submitHandler: function (form, event, validator) {
            $(form).ajaxSubmit(function (data) {
                var result = data.resCode;
                if (result == 1) {
                    layer.alert(data.resMsg + ",3秒<br>后自动跳转至我的账户", function(index){
        				window.location.href = "/mobile/usercenter/main.html";
        			});
                    setTimeout(function () {
                        window.location = "/mobile/usercenter/main.html";
                    }, 3000);
                } else {
                    layer.alert(data.resMsg);
                }
            });
        }
    });
    formClear($("#withdrawals-form"));
    function formClear(form) {
        var inputTexts = form.find("input[type ='text']");
        var inputPasswords = form.find("input[type ='password']");
        var inputs = $.merge(inputTexts,inputPasswords); 
        for (var i = 0, len = inputs.length; i < len; i++) {
            $(inputs[i]).val("");
        }
    }
});